<template>
  <!--视频资料新增/编辑弹窗-->
  <a-modal  :maskClosable="false"
            :title="mdl.dialogTitleMap[mdl.dialogStatus]"
            :width="1000"
            @ok="mdl.dialogStatus === 'create' ? createData() : updateData()"
            v-model="mdl.visible"
            :confirm-loading="loading"
  >
    <a-form-model :model="mdl.formData" :rules="rules">
      <a-form-model-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="视频名称"
        prop="videoName"
      >
        <a-input placeholder="" v-model="mdl.formData.videoName"/>
      </a-form-model-item>
      <a-form-model-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="视频详情"
      >
        <a-textarea :rows="4" v-model="mdl.formData.videoInfo"/>
      </a-form-model-item>
      <a-form-model-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="视频积分"
        prop="videoIntegral"
      >
        <a-input-number v-model="mdl.formData.videoIntegral" :min="1" :max="50"/>
      </a-form-model-item>
      <a-form-model-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="学时"
        prop="period"
      >
        <a-input-number v-model="mdl.formData.period" :min="1" :max="50"/>
      </a-form-model-item>
      <a-form-model-item
        :labelCol="mdl.labelCol"
        :wrapperCol="mdl.wrapperCol"
        label="视频上传"
        prop="liveFileNo"
      >
        <videoCom @getVideoFile="getVideoFile" :msg="mdl.formData.videoFileName" :id="mdl.formData.liveFileNo"></videoCom>
      </a-form-model-item>
    </a-form-model>
    <div>

    </div>
  </a-modal>
</template>
<script>
  import moment from 'moment';
  import videoCom from '@/components/videoCom'
  import {studyvideoup,studyvideoinsert} from '@/api/invoice'
  export default {
    components: {
      videoCom
    },
    props: {
      /*   -------弹窗--------*/
      mdl: [Array,Object,String],
    },
    data() {
      return {
        file: {},
        loading: false,
        rules: {
          videoName: [{ required: true, message: '视频名称不能为空', trigger: 'bluer' }],
          videoIntegral: [{ required: true, message: '视频积分不能为空', trigger: 'bluer' }],
          period: [{ required: true, message: '视频学时不能为空', trigger: 'bluer' }],
          liveFileNo: [{ required: true, message: '视频不能为空', trigger: 'bluer' }],
        }
      }
    },
    inject: ['upShow'],

    created() {

    },
    watch: {

    },
    computed: {

    },
    methods: {
//          新增
      createData() {
        if(this.mdl.formData.videoFileNo==null || this.mdl.formData.videoFileNo =='' ||this.mdl.formData.period==null || this.mdl.formData.period =='' || this.mdl.formData.videoIntegral == '' || this.mdl.formData.videoIntegral==null) {
          this.upShow(2,'内容不能为空')
        }else {
          this.loading = true
          const parameter = {
            id: '',
            uploadTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
            videoFileName: this.mdl.formData.videoFileName,
            videoFileNo: this.mdl.formData.videoFileNo,
            videoFilePath: this.mdl.formData.videoFilePath,
            videoInfo: this.mdl.formData.videoInfo,
            videoIntegral: this.mdl.formData.videoIntegral,
            videoName: this.mdl.formData.videoName,
            period: this.mdl.formData.period
          }
          studyvideoinsert(parameter).then(res => {
            this.loading = false
            if (res.code === 200) {
              this.upShow(1, "新增成功")
              this.mdl.visible = false
              this.$emit('handleSearch')
            } else {
              this.upShow(2, res.msg)
            }
          }).catch(err => {
            this.loading = false
            this.upShow(2)
          })
        }
      },
//      编辑
      updateData() {
          if(this.mdl.formData.videoFileNo==null || this.mdl.formData.videoFileNo =='' ||this.mdl.formData.period==null || this.mdl.formData.period =='' || this.mdl.formData.videoIntegral == '' || this.mdl.formData.videoIntegral==null) {
            this.upShow(2,'内容不能为空')
          }else {
            const parameter = {
              id: this.mdl.formData.id,
              uploadTime: this.mdl.formData.uploadTime,
              videoFileName: this.mdl.formData.videoFileName,
              videoFileNo: this.mdl.formData.videoFileNo,
              videoFilePath: this.mdl.formData.videoFilePath,
              videoInfo: this.mdl.formData.videoInfo,
              videoIntegral: this.mdl.formData.videoIntegral,
              videoName: this.mdl.formData.videoName,
              period: this.mdl.formData.period
            }
            studyvideoup(parameter).then(res => {
              if(res.code === 200) {
                this.upShow(1,"编辑成功")
                this.mdl.visible = false
                this.$emit('handleSearch')
              } else {
                this.upShow(2,res.msg)
              }
            }).catch(err => {
              this.upShow(2)
            })
          }
      },
//      获取上传的视频数据
      getVideoFile(val) {
          this.mdl.formData.videoFileName = val.fileName;
          this.mdl.formData.videoFileNo = val.fileNo;
          this.mdl.formData.videoFilePath = val.fileUrl;
          this.mdl.formData.period = val.filePeriod;
          if(this.mdl.formData.videoName == '') {
            this.mdl.formData.videoName = val.fileName;
          }
      }
    }
  }
</script>